# 爬虫 url 管理器


class UrlManager:
    def __init__(self):
        self.new_urls = set()
        self.old_urls = set()

    # 添加新的 url
    def add_new_url(self, url):
        if url is None:
            return
        if url not in self.new_urls and url not in self.old_urls:
            self.new_urls.add(url)

    # 添加新的 urls
    def add_new_urls(self, urls):
        if urls is None or len(urls) == 0:
            return
        for url in urls:
            self.add_new_url(url)

    # 判断是否有新的 url
    def has_new_url(self):
        return len(self.new_urls) > 0

    # 获取新的 url
    def get_new_url(self):
        new_url = self.new_urls.pop()
        self.old_urls.add(new_url)
        return new_url

    # 添加旧的 url
    def add_old_url(self, url):
        if url is None:
            return
        if url not in self.old_urls:
            self.old_urls.add(url)

    # 添加旧的 urls
    def add_old_urls(self, urls):
        if urls is None or len(urls) == 0:
            return
        for url in urls:
            self.add_old_url(url)

    # 判断是否有旧的 url
    def has_old_url(self):
        return len(self.old_urls) > 0

    # 获取旧的 url
    def get_old_url(self):
        if len(self.old_urls) == 0:
            return None
        old_url = self.old_urls.pop()
        return old_url